import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const state = {
	count: 1,
	slogin:false,
}

const mutations = {
	loginS(state){
		state.slogin=true;
	},

	
	add(state) {
		state.count++;
	},
	reduce(state,n) {
		state.count-=n;
	},

}

const getters = {
	count: function(state) {
		return state.count += 100;
	}
}

const actions = {
	addAction(context) {
		context.commit('add', 10);
		setTimeout(() => {
			context.commit('reduce')
		}, 3000);
		console.log('111'); //比上面的时间器先执行 说明是异步的
	},
	reduceAction({
		commit
	}) {
		commit('reduce');
	}
}

export default new Vuex.Store({
	state,
	mutations,
	getters
})